package com.routz.bitblog.blog.security.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
@ResponseBody
public class ExceptionHandlerAdvice {
    private final Logger logger = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);

    private void log(Exception e) {
        logger.error(e.getMessage(), e);
    }

    @ExceptionHandler(BaseException.class)
    @ResponseStatus(value= HttpStatus.I_AM_A_TEAPOT)
    public String baseException(BaseException e) {
        log(e);
        return "Wow";
    }
}
